package hibernate_basic.Zexercise.topic02;

import hibernate_basic.Persistence.comment_persitence.Person;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 * @author Administrator
 * @create 2019-01-01 10:22
 * @desc 查询员工信息
 **/
public class Query {

    public static void main(String args[]){
        Configuration config=new Configuration();
        config.configure("hibernate_basic/Zexercise/topic02/config/hibernate.cfg.xml");
        SessionFactory factory = config.buildSessionFactory();
        Session session=factory.openSession();
        Transaction tion=session.beginTransaction();
        /*
        使用一级缓存查询数据
         */
        Person person=session.get(Person.class,15);
        System.out.println(person.getName());
        Person person2=session.get(Person.class,15);
        System.out.println(person2.getName());
        /*
        使用二级缓存查询数据
         */
        Session session1=factory.openSession();
        Person person1=session1.get(Person.class,15);
        System.out.println(person1.getName());
    }
}
